home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Think Class Libraries / WASTE TCL 1.8 / WASTE TCL 1.8 ƒ / Readme < prev    next >
Encoding:
Text File  |  1995-11-12  |  16.2 KB  |  265 lines  |  [TEXT/ttxt]

  1. CWASTEText Classes
  2. A set of classes for using WASTE with the Think Class Libraries
  3. by Dan Crevier <mailto:dan@rhino.harvard.edu>
  4. Signficant contributions by Mark Alldritt
  5. version 1.8
  6. November 4, 1995
  7.  
  8. Introduction
  9.  
  10.     This is a set of classes I've written to use Marco Piovanelli's text edit replacement WASTE with the Think Class Libraries.  It only works with versions 2.0.3 or later of TCL.  It should work with every version of WASTE, but it is hard to test everything.  It has been tested with versions up to 1.2a3.  It has been tested with Symantec C++ 8.0, Think C 7.0 and CodeWarrior 7.
  11.      For more information on WASTE, see <http://cirrus.sprl.umich.edu>.
  12.      I wanted to use WASTE in one of my applications mainly for the ability to use more than 32K of text, and to use inline input for Japanese.  I am releasing these classes as public domain, so you are free to use them as you see fit.  Remember to give Marco Piovanelli credit if you use WASTE, and you can give me some credit if you feel like it.  If you use these classes, I'd be very interested in any bug reports (especially if they include fixes) and any improvements anyone makes.  I'd like to thank Marco Piovanelli both for making WASTE available and for his help in figuring out how to get it to work with the class libraries.
  13.  
  14.      If you have used a previous version of the classes, see the what's new section.
  15.  
  16.     There are 6 classes included.  They are:
  17.      CWASTEText - a subclass of CAbstractText which is much like CStyleText
  18.      CWASTEDlgText - a subclass of CWASTEText which is a bit like
  19.              CDialogText, but without all of the validation features.  It
  20.              has a border, broadcasts changes when the text changes,
  21.              and passes return, enter and escape to the supervisor.
  22.      CTSMSwitchboard - a subclass of CSwitchboard which deals
  23.              with Text Service Manager events.
  24.      CWASTEEditTask - a class for handling undo with CWASTEText with WASTE 1.0
  25.      CWASTEStyleTask - a class for handling undo'ing style changes with CWASTEText
  26.               with WASTE 1.0
  27.      CWASTETask - a class for handling undo with WASTE 1.1.
  28.  
  29.      I've also included a slightly modified version of TinyEdit, called WASTEEdit, which uses WASTE as a simple example program.
  30.  
  31.      You are free to use these classes in any of your products (freeware, shareware, or commercial).
  32.  
  33. Adding WASTE Support
  34.  
  35.      If you wish to use these classes in your application, you need to add the following to your application class:
  36.  
  37.      Near the top:
  38.  
  39. #include "WASTE.h"
  40. #ifndef __SCRIPT__
  41. #include <Script.h>
  42. #endif
  43.  
  44. #include "CTSMSwitchboard.h"
  45. #include "CTSMDesktop.h"
  46.  
  47. static Boolean    TSMAvailable(void);
  48.  
  49. extern CDesktop *gDesktop;
  50.  
  51. short gUsingTSM = false;
  52.  
  53.      In the constructor:
  54.  
  55.     gUsingTSM = TSMAvailable() && (InitTSMAwareApplication()==noErr);
  56.  
  57.      In the destructor:
  58.  
  59.     if (gUsingTSM) CloseTSMAwareApplication();
  60.  
  61.      Functions to add:
  62.  
  63. // make TSMSwitchboard
  64. void CEditApp::MakeSwitchboard( void)
  65. {
  66.     if (gSystem.hasAppleEvents && gUsingTSM)
  67.     {
  68.         FailOSErr(WEInstallTSMHandlers());
  69.     }
  70.     itsSwitchboard = (CSwitchboard *)new CTSMSwitchboard();
  71.     itsSwitchboard->InitAppleEvents();
  72. }
  73.  
  74. // make TSMDesktop
  75. void CEditApp::MakeDesktop(void)
  76. {
  77.     gDesktop = (CDesktop *)new CTSMDesktop();
  78. }
  79.  
  80. static Boolean TSMAvailable(void)
  81. {
  82.     long    response;
  83.     
  84.     return (Gestalt(gestaltTSMgrVersion, &response)==noErr);
  85. }
  86.  
  87.      To header file:
  88.  
  89. virtual void MakeSwitchboard(void);
  90. virtual void MakeDesktop(void);
  91.  
  92.      See WASTEEdit for an example.  Most of this stuff is to provide inline input.  Even if you don't use Japanese on your system, I recommend leaving the support there for those that do have inline input.
  93.  
  94. CWASTEText
  95.  
  96.      CWASTEText is a subclass of CAbstractText, and is very similar to CStyleText.  In addition, I have added the following functions:
  97.  
  98.      StopInlineSession() - Stops the current inline input session
  99.           and validates the text.
  100.      InsertWithStyle() - Lets you insert some text and it's
  101.           corresponding StScrpHandle information all in one step.
  102.      InsertWithStyleSoup() - Lets you insert some text and it's
  103.           corresponding StScrpHandle information and soup all in one step.
  104.           (WASTE 1.1 only)
  105.      Clear() - clears the text in the class without any excess
  106.           highlighting.
  107.      CopyRangeWithStyle() - gets the text and styles for a range
  108.           of text all in one step.
  109.      CopyRangeWithStyleSoup() - gets the text, styles, and soup for a range
  110.           of text all in one step. (WASTE 1.1 only)
  111.      SetOutlineHighlighting() - turns outline highlighting on or off.  Returns old
  112.           setting.
  113.      SetFontNumberAll() - sets the font of all of the text.
  114.      SetFontNameAll() - sets the font of all of the text.
  115.      SetFontSizeAll() - sets the size of all of the text.
  116.      SetFontStyleAll() - applies a style to all of the text
  117.      TempSelectAll() - temporarily selects all of the text while deactivating the text
  118.           and turning off outline hilighting so that the selection won't show up.  It can
  119.           be restored by Restore selection.  This is useful when you want to apply
  120.           something to all of the text without seeing all of the text flash.  It is a
  121.           protected routine used by Clear() and the Set*All() functions.
  122.      SetFontColor() - sets the color of the selection
  123.      SetFontColorAll() -sets the color of all of the text
  124.      InsertPicture() - inserts a picture at the current insertion point (WASTE 1.1 only)
  125.      InsertSound() - inserts a sound at the current insertion point (WASTE 1.1 only)
  126.      InstallDragHandlers() - installs the necessary handlers to receive drags (see
  127.           Drag and Drop section below)
  128.      RemoveDragHandlers() - removes drag handlers
  129.      CopyWithStyleSoup() - copies text with style and soup information (WASTE 1.1 only)
  130.      InstallTabHandlers() - installs hooks for using tab code (with CWASTE 1.1 or later only)
  131.      GetRunInfo() - gets the information about the style run at the given offset
  132.      GetChar() - gets the character at an offset
  133.      SetLineWidth() - changes the line width (where lines wrap).  -1 wraps to the pane width.
  134.  
  135.      TCL isn't good at supporting text without fixed height lines.  SetWholeLines(true) doesn't work well.  I set the scrolling steps to 12 vertically and 4 horizontally when it's in a scroll pane.  Something more intelligent could probably be done.
  136.  
  137. CWASTEDlgText
  138.  
  139.      CWASTEDlgText was made to provide some of the funcitonality of CDialogText.  A dialogTextChanged message is broadcast when the text is changed.  This wasn't easy for text being entered with inline input, but I think I have it working with a WEPostUpdate routine.  It may be broadcasting the message more often than it needs to, but that's ok with me.
  140.      It also has a border, just like CDialogText, and passes tab, return, enter, and escape to the supervisor instead of typing them.
  141.      I added the GetTextString() method to get the text into a Str255.
  142.  
  143. CTSMSwitchboard
  144.  
  145.      This is a subclass of CSwitchboard which handles Text Service Manager events.
  146.  
  147. CTSMDesktop
  148.  
  149.      This is a subclass of CDesktop that lets the Text Service Manager set the cursor.
  150.  
  151. Undo Support
  152.  
  153.      With WASTE 1.0, the two classes CWASTEEditTask and CWASTEStyleTask are used for undo support.  With WASTE 1.1, the class CWASTETask is used to provide undo support using WASTE 1.1's built in undo support.   You need to add the appropriate classes to your project.  When using CWASTETask, you must add the string "Drag" to STR# resource 130 so you get the "Undo Drag" message in the edit window.
  154.  
  155. Drag and Drop support
  156.  
  157.      WASTE 1.1 supports dragging and dropping of text.  You don't have to do any work to make it so that users can drag text out of CWASTEText panes.  If you want to let the user drag text into a CWASTEText pane, you should call CWASTEText::InstallDragHandlers() for that pane.  Note: you cannot call InstallDragHandlers() for more than one CWASTEText pane per window.  I hope to be able to remove this restriction soon, but it will require some minor modifications to WASTE itself, or more support for Drag and Drop in TCL.  Before you can call InstallDrag Handlers, you must add the following to your application class:
  158.  
  159. At the top:
  160.  
  161. #include <FragLoad.h>
  162. #include <Drag.h>
  163. static Boolean    DragAndDropAvailable(void);
  164. Boolean gHasDragAndDrop = false;
  165.  
  166. In the constructor:
  167.  
  168.     gHasDragAndDrop = DragAndDropAvailable();
  169.  
  170. Anywhere else:
  171.  
  172. /******************************************************************************
  173.  DragAndDropAvailable - returns true if drag and drop is available
  174.  ******************************************************************************/
  175.  
  176. static Boolean DragAndDropAvailable(void)
  177. {
  178.     long response;
  179.  
  180.     if (Gestalt(gestaltDragMgrAttr, &response) != noErr) return false;
  181.     if ((response & (1 << gestaltDragMgrPresent)) == 0) return false;
  182.     if ((Ptr)InstallTrackingHandler == kUnresolvedSymbolAddress) return false;
  183.     return true;
  184. }
  185.  
  186. Using with TCL 1.1.3
  187.  
  188.      Romain Vignes modified the classes to work with TCL 1.1.3.  I haven't tested it out myself.  You need to add the following to your prefix:
  189. #define __LONGCOORDINATES__    1                        // Long coordinates services are 
  190.                                                     // handled by the TCL.
  191.                                                     
  192. #define TCL_VERSION         0x01010300                // Your version of TCL
  193.  
  194. WASTE Object Handler Archive
  195.  
  196.      If WASTE_OBJECT_ARCHIVE is defined, CWASTEText will use Michael Kamprath's WASTE Object Handler Archive for the object handlers.  In this case, you don't need to add the WASTE TCL sound icon resource (but you must include the Object Archive one).  It also adds the function InsertFSSpec().
  197.      The object archive included with WASTE 1.2a3 doesn't include the HFS stuff, so InsertFSSpec() won't work with that version.  It also uses other filenames.  I haven't put in explicit support for this version, I'm going to wait to see how it evolves.
  198.  
  199. WASTEEdit
  200.  
  201.      WASTEEdit is a slightly modified version of TinyEdit to get it to work with WASTE.  I tried to do the minimum modifications necessary to get it to work, so I haven't added any functionality.  With a little work, I think a nice application could be made out of it.  Right now, it's almost 10 times as big as WASTE Demo, and doesn't do quite as much.  It would be really great if someone wanted to add all the scripting support to it, so we would have a nice replacement for the Scriptable Text Editor.
  202.      I compiled this version with the WASTE Object Handler Archive, CWASTE 1.2a3 with Internet Config support (so cmd-clicking URL's should work), and the tab support code.  You may need to change the #defines in the prefix options and change the files that are included in the project.
  203.  
  204. Using with Visual Architect
  205.  
  206.      Michael Grinner got me started on using WASTE-TCL with VA.  Basically, if VA_COMPATIBLE_IO is defined to 1, CWASTEText has the same PutTo and GetFrom routines as CEditText and CWASTEDlgText has the same PutTo and GetFrom routines as CDialogText.  Therefore, you can define new classes in VA with names like CVAWASTEText and CVAWASTEDlgText that are based on CEditText and CDialogText, with library classes CWASTEText and CWASTEDlgText.  Then, you can make objects of type CVAWASTEText and CVAWASTEDlgText in your VA views.  I've included a simple demo.  Note that CWASTEDlgText doesn't handle all of the validation stuff that CDialogText does... 
  207.  
  208. What's new
  209.  
  210.      • Version 1.1
  211.      Unfortunately I haven't kept track of the changes made in the classes very well.  There were many changes, most of them for improved error checking.  Marco Piovanelli and Mark Alldritt made many contributions, and I made some changes myself.  Also, I have used the classes with my port of WASTE to C.  In the file CWASTEText.cpp, you need to define/undefine CWASTE depending on whether or not you are using the C version of WASTE.
  212.  
  213.      • Version 1.2
  214.      The most significant change for this version is support for WASTE 1.1.  It includes drag and drop support as well as support for inserting pictures.  Also, I have incorporated some bug fixes by Martin Fricke and some of my own.
  215.  
  216.      • Version 1.3
  217.      Added functions InsertWithStyleSoup and CopyWithStyleSoup which insert/copy the text, styles, and soup. 
  218.      As of WASTE 1.1a5 and CWASTE1.1r7 and later, the way tab code is handled is different.  In CWASTEText.h, #define WASTE_TABS if you are using one of these new versions, and WASTE_AUTO_TABS if you want the tab handlers to be automatically installed.  Otherwise, you have to install InstallTabHandlers for each CWASTEText that you want to use tabs in.
  219.  
  220.      • Version 1.4
  221.      Added sound handlers as donated by Leonard Rosenthal.  Added InsertSound() to add sounds.  You must add the resource file "Sound Icon.rsrc" to your project.
  222.      Modified CEditDoc to save/load style and soup information.
  223.      Stopped including WASTEEdit 1.0 (WASTE 1.1 is very stable)
  224.      If you make Brian L. Matthews <blm@halcyon.com>'s modifications to TCL, click-through will be supported (you can drag something out of a window even if it isn't in front).  Note:  The demo isn't compiled with this support.
  225.  
  226.      • Version 1.5
  227.      Changed to work with WASTE 1.1a7 (CWASTE 1.1r12) or later.  Will not work with earlier version of WASTE 1.1.
  228.      Note: IViewTemp won't work for specifying non-editable text because macWE isn't set up before specify is called, so it can't set the readonly flag for the WASTE instance.  It shouldn't be hard to fix this, or work around it.
  229.      Added post update proc to make it keep up with typing that goes outside of the visible area during inline input, as suggested by Martin Sladok.
  230.      There are probably other changes I forgot to document.
  231.  
  232.      • Version 1.6
  233.      Modified UpdateMenu() to check the correct color item in the menu.
  234.      Added WASTETask class to provide undo support using WASTE 1.1 built in support (thanks to help from Jud Spencer).  It may not allow styling of pane's with styleable==false.
  235.      Pre and post update routines moved to static functions.
  236.  
  237.      • Version 1.7     7/2/95
  238.      Added a bunch of improvements by Martin Sladok for dealing with multiple CWASTEText's in one window for printing and undo'ing.
  239.      Got rid of curWASTEText static variable, and instead store the CWASTEText * as the refcon for the WASTE instance, and use that in the various callback routines.
  240.      Added some PutTo() and GetSome() routines suggested by Martin Sladok.  I have not tested them.
  241.      Changed the constructor and I() function to optionally let you turn on/off objects, undo support, drag and drop, outline highlighting, and offscreen drawing.
  242.      Changed the way CTSMSwitchboard works -- now there is also a CTSMDesktop.
  243.      If already typing, WEKey() doesn't make a new CWASTETask.
  244.      Fixes in CalcWERects() from Martin Sladok.
  245.      Now tested with SC++ 8.0, and WASTEEdit includes a SC++ 8.0 project
  246.  
  247.      • Version 1.8    11/4/95
  248.      ResizeFrame only calls WECalText() if width changes.
  249.      Added GetRunInfo() to get the WASTE information about style runs.
  250.      Aded GetChar() to get the character at an offset, taking two-byte scripts into account.
  251.      Added SetLineWidth() from Jan Petersen.
  252.      Simplications of CTSM* by Steve Gilardi.
  253.      Fixed object I/O stuff (thanks everyone)
  254.      Updated to latest TCL style of prefixing TCL routines with "TCL", like TCLForgetObject().
  255.      When using WASTE 1.2a3 or later, takes advantage of the new redraw flag, so redrawing will be correctly enabled/disabled in the routines that take a redraw flag.  This gets rid of the flickering effects that took place with older versions of WASTE.
  256.      The #defines are now done more intelligently.  See CWASTEText.h for details on what each one does.  If you want to change a #define, I suggest you put the #define in a prefix file, and that will override the default in CWASTEText.h.
  257.      Patches to work with TCL 1.1.3 by  Romain Vignes.  See comments in section above.
  258.      Removed Notify(NULL)'s.  At least in some cases they aren't the appropriate thing to do.  You may need to call it on your own if you do something to a CWASTEText that you don't want the user to undo.
  259.      CEditText and CDialogText compatible I/O routines for use with VA, as suggested by Michael Grinner when VA_COMPATIBLE_IO is defined.  This makes it easy to use WASTE-TCL in VA.  A demo is included.
  260.      Printing seems to sometimes break lines across pages.  I haven't figured out why yet, any help would be appreciated.
  261.  
  262. Dan Crevier
  263. <mailto:dan@rhino.harvard.edu>
  264. <http://rhino.harvard.edu/dan/home.html>
  265.